/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package heartinjava;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JLabel;

/**
 *
 * @author TIENDAT
 */

public class ConnectServer extends Play {
    
    ConnectServer(final HeartInJava m_main, final KhungBanCo gui) 
    {
        this.m_Main = m_main;
        this.gui = gui;
    }

    @Override
    public void Enter()
    {
        gui.container.removeAll();

//        URL path = getClass().getResource("resources/bg.jpg");
  //      JLabel bg= new JLabel(new ImageIcon(path));
    //    
      //  bg.setBounds(gui.container.getX(), gui.container.getX(),gui.container.getWidth(), gui.container.getHeight());
        //gui.container.add(bg);      

        JButton btnBack = new JButton("Done");
        btnBack.setBounds(350, 300, 150, 30);
        btnBack.addActionListener(new ActionListener() 
        {
            public void actionPerformed(ActionEvent e) 
            {
                m_Main.SwitchState(KhaiBao.MENU);
            }
        });

        btnBack.addMouseListener(new MouseListener() 
        {
            public void mouseClicked(MouseEvent e) {}
            public void mousePressed(MouseEvent e) {}
            public void mouseReleased(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
        });
        
        gui.container.add(btnBack,0);
        gui.repaint();
        Connect();
    }

    private void Connect()
    {
        m_Main.IsServer(KhaiBao.DEFAULTPORT);
        if (m_Main.getServer().isConnect == true) 
        {
            m_Main.SwitchState(KhaiBao.WAIT);
        } 
        else 
        {
            m_Main.setType(-1);
            JLabel note = new JLabel();
            note.setForeground(Color.white);
            note.setText("Không thể vào phòng được... !!!");
            note.setBounds(280, 250, 300, 30);
            gui.container.add(note, 0);
        }
    }
}
